var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var app = getApp();

Page({
  data: {
    storeList: []
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    this.getStoreList();
  },
  getStoreList (){
    let that = this;
    util.request(api.MyManUrl+"?token="+app.globalData.token).then(function (res) {
      if (res.code === "0000") {
        that.setData({
          storeList: res.list
        });
      }else if(res.code==="0008"){
        wx.navigateTo({
          url: '/pages/auth/btnAuth/btnAuth',
        })
      }
    });
  },
  storeAddOrUpdate (event) {
    wx.navigateTo({
      url: '/pages/ucenter/storeAdd/storeAdd?id=' + event.currentTarget.dataset.storeId
    })
  },
  deleteStore(event){
    let that = this;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success: function (res) {
        if (res.confirm) {
          let storeId = event.target.dataset.storeId;
          util.request(api.StoreDelete+"?token="+app.globalData.token, { id: storeId },'POST', 'application/json').then(function (res) {
            if (res.code === "0000") {
              that.getStoreList();
            }else if(res.code==="0008"){
              wx.navigateTo({
                url: '/pages/auth/btnAuth/btnAuth',
              })
            }
          });
        }
      }
    })
    return false;
    
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})